let id = 0;
export default class Dep {
    constructor() {
        this.stack = [];
        this.id = id++;
    }
    depend() {
        Dep.target.addDep(this);
    }
    addSub(watcher) {
        this.stack.push(watcher);
    }
    notify() {
        this.stack.forEach(watcher => watcher.update())
    }
}

Dep.target = null;
// 为了考虑computed的watcher，computed里面除了要将computed的watcher收集之外，还需要将渲染watcher收集起来，需要用数组去管理
const stack = [];

// 给Dep.target赋值
export function pushTarget(watcher) {
    if (Dep.target) { // 说明进来了computed watcher, 将渲染watcher添加到栈中
        stack.push(Dep.target);
    }
    Dep.target = watcher;
}

// 将Dep.target清空
export function popTarget() {
    Dep.target = stack.pop();
}